package com.qyhl.module_practice.donate;


import com.qyhl.module_practice.common.PracticeUrl;
import com.qyhl.webtv.basiclib.utils.network.EasyHttp;
import com.qyhl.webtv.basiclib.utils.network.callback.SimpleCallBack;
import com.qyhl.webtv.basiclib.utils.network.exception.ApiException;
import com.qyhl.webtv.commonlib.common.CommonUtils;
import com.qyhl.webtv.commonlib.entity.civilized.PracticeDonateBean;

import java.util.List;

public class PracticeDonateListModel implements PracticeDonateListContract.PracticeDonateListModel {
    private PracticeDonateListPresenter mPresenter;

    PracticeDonateListModel(PracticeDonateListPresenter mPresenter) {
        this.mPresenter = mPresenter;
    }

    @Override
    public void getList(String page) {

        EasyHttp.get(PracticeUrl.GET_PRACTICE_DONATE_LIST)
                .params("siteId", CommonUtils.getInstance().getSite() + "")
                .params("page", page)
                .execute(new SimpleCallBack<List<PracticeDonateBean>>() {
                    @Override
                    public void onError(ApiException e) {
                        if (e.getCode() == 202) {
                            mPresenter.setError("暂无任何捐赠点！", !page.equals("1"));
                        } else {
                            mPresenter.setError("获取列表失败，请重新尝试！", !page.equals("1"));
                        }
                    }

                    @Override
                    public void onSuccess(List<PracticeDonateBean> practiceDonateBeans) {
                        if (practiceDonateBeans!= null && practiceDonateBeans.size() > 0) {
                            mPresenter.setList(practiceDonateBeans, !page.equals("1"));
                        } else {
                            mPresenter.setError("暂无任何捐赠点！", !page.equals("1"));
                        }
                    }
                });
        
    }
}
